#include "tabulate.h"

tabulate::tabulate ()
{
  ta = NULL;
  cod_vec = NULL;
}

void tabulate::add_table (table *new_table)
{
  ta = new_table;
}

int tabulate::add_vector (Vector *new_vector)
{
  type_of_vec which;

  if (new_vector != NULL)
	which = new_vector->get_type ();
  else
  {
	cout << "Unable to add the Codevec." << endl;
	return 0;
  }

  if (which != codevec)
  {
	cout << "Not a Codevec" << endl;
	return 0;
  }
  else
  {
	cod_vec = new_vector;
	return 1;
  }
}

table* tabulate::tabulate_table ()
{
  if ((ta == NULL) || (cod_vec == NULL))
  {
	cout << "Table or Codevec not initalized!!" << endl;
	return 0;
  }
  else
  {
	tab ();
	return ta;
  }
}

table* tabulate::tabulate_table (table *new_table, Vector *new_vector)
{
  type_of_vec which;

  ta = new_table;
  if (new_vector != NULL)
	which = new_vector->get_type ();
  else
  {
	cerr << "Unable to add new Codevec." << endl;
	return 0;
  }
  if (which != codevec)
  {
	cerr << "Not a Codevec!." << endl;
	return 0;
  }
  else
	cod_vec = new_vector;

  if (ta == NULL)
  {
	cerr << "Unable to create table." << endl;
	return 0;
  }
  else
  {
	tab ();
	return ta;
  }
}

int tabulate::tab ()
{
  int size = ((Codevec *) cod_vec)->get_size (), i;
  string temp;

  num = 0;
  for (i = 1; i <= size; i++)
  {
	temp = ((Codevec *) cod_vec)->get (i);
	ta->add (temp, 1);
	num++;
  }
  return num;
}